﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NasuTek.Shion.Extencibility;
using System.Windows.Forms;

namespace Shion.BasicChannelAdminCommands
{
    public class Plugin : IPlugin
    {
        #region IPlugin Members

        public void Load(ExtencibilityManager e)
        {
            new BasicChannelAdminCommands(e);
        }

        #endregion
    }

    public class BasicChannelAdminCommands
    {
        ExtencibilityManager em;
        public BasicChannelAdminCommands(ExtencibilityManager e)
        {
            em = e;

            ToolStripMenuItem control = new ToolStripMenuItem("Kick/Ban Control");
            ToolStripMenuItem modecontrol = new ToolStripMenuItem("Channel Mode Control");

            ToolStripMenuItem kick = new ToolStripMenuItem("Kick");
            kick.Click += new EventHandler(kick_Click);

            ToolStripMenuItem kickwhy = new ToolStripMenuItem("Kick (Why)");
            kickwhy.Click += new EventHandler(kickwhy_Click);

            ToolStripMenuItem ban = new ToolStripMenuItem("Ban");
            ban.Click+=new EventHandler(ban_Click);

            ToolStripMenuItem bankick = new ToolStripMenuItem("Ban/Kick");
            bankick.Click += new EventHandler(bankick_Click);

            ToolStripMenuItem bankickwhy = new ToolStripMenuItem("Ban/Kick (Why)");
            bankickwhy.Click += new EventHandler(bankickwhy_Click);

            control.DropDown.Items.Add(kick);
            control.DropDown.Items.Add(kickwhy);
            control.DropDown.Items.Add(ban);
            control.DropDown.Items.Add(bankick);
            control.DropDown.Items.Add(bankickwhy);

            ToolStripMenuItem op = new ToolStripMenuItem("Op");
            op.Click += new EventHandler(op_Click);
            ToolStripMenuItem deop = new ToolStripMenuItem("Deop");
            deop.Click += new EventHandler(deop_Click);
            ToolStripMenuItem hop = new ToolStripMenuItem("Hop");
            hop.Click += new EventHandler(hop_Click);
            ToolStripMenuItem dehop = new ToolStripMenuItem("Dehop");
            dehop.Click += new EventHandler(dehop_Click);
            ToolStripMenuItem vop = new ToolStripMenuItem("Vop");
            vop.Click += new EventHandler(vop_Click);
            ToolStripMenuItem devop = new ToolStripMenuItem("Devop");
            devop.Click += new EventHandler(devop_Click);

            modecontrol.DropDown.Items.Add(op);
            modecontrol.DropDown.Items.Add(deop);
            modecontrol.DropDown.Items.Add(hop);
            modecontrol.DropDown.Items.Add(dehop);
            modecontrol.DropDown.Items.Add(vop);
            modecontrol.DropDown.Items.Add(devop);

            e.NickMenu.Items.Add(control);
            e.NickMenu.Items.Add(modecontrol);
        }

        void devop_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem i in em.NickListView.SelectedItems)
            {
                em.Clients[em.activeServer].Devoice(em.activeChannel, i.Text);
            }
        }

        void vop_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem i in em.NickListView.SelectedItems)
            {
                em.Clients[em.activeServer].Voice(em.activeChannel, i.Text);
            }
        }

        void dehop_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem i in em.NickListView.SelectedItems)
            {
                em.Clients[em.activeServer].Dehalfop(em.activeChannel, i.Text);
            }
        }

        void hop_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem i in em.NickListView.SelectedItems)
            {
                em.Clients[em.activeServer].Halfop(em.activeChannel, i.Text, NasuTek.Shion.Agent.Priority.High);
            }
        }

        void deop_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem i in em.NickListView.SelectedItems)
            {
                em.Clients[em.activeServer].Deop(em.activeChannel, i.Text);
            }
        }

        void op_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem i in em.NickListView.SelectedItems)
            {
                em.Clients[em.activeServer].Op(em.activeChannel, i.Text);
            }
        }

        void kickwhy_Click(object sender, EventArgs e)
        {
            throw new NotImplementedException();
        }

        void kick_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem i in em.NickListView.SelectedItems)
            {
                em.Clients[em.activeServer].RfcKick(em.activeChannel, i.Text);
            }
        }

        void bankickwhy_Click(object sender, EventArgs e)
        {
            
        }

        void bankick_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem i in em.NickListView.SelectedItems)
            {
                em.Clients[em.activeServer].Ban(em.activeChannel, em.Address(em.activeServer, i.Text, 1));
                em.Clients[em.activeServer].RfcKick(em.activeChannel, i.Text);
            }
        }

        void ban_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem i in em.NickListView.SelectedItems)
            {
                em.Clients[em.activeServer].Ban(em.activeChannel, em.Address(em.activeServer, i.Text, 1));
            }
        }
    }
}
